package com.mcintyret.site.security;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.security.authentication.dao.ReflectionSaltSource;
import org.springframework.security.authentication.dao.SaltSource;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;

/**
 * User: mcintyret2
 * Date: 08/04/2012
 */

@Configuration
@ImportResource("classpath:security.xml")
@PropertySource("classpath:security.properties")
public class SecurityConfig {

    @Value("${users.salt.source}")
    private String usersSaltSource;

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new ShaPasswordEncoder(256);
    }

    @Bean
    public SaltSource saltSource() {
        ReflectionSaltSource saltSource =  new ReflectionSaltSource();
        saltSource.setUserPropertyToUse(usersSaltSource);
        return saltSource;
    }

}
